import os
import math
import yaml
from flask.ext.wtf import Form
from wtforms import StringField, SubmitField, SelectField
from wtforms.validators import Required, Optional,Regexp
from flask_wtf.file import FileAllowed, FileRequired, FileField
from rookout.base import (list_dir, read_file)
from operator import itemgetter

class UploadForm(Form):
    workdir = os.path.split(os.path.abspath(__file__))[0]
    config = yaml.load(read_file(os.path.join(workdir, 'config.yaml')))
    ppt_dir = config['ppt_dir']
    dir_list = os.listdir(ppt_dir)
    dir_list.append("")
    levelone_Dir = SelectField('一级目录:', choices = [(key, key) for key in dir_list])
    secLevel_Dir = StringField('二级目录:',validators=[Optional()])
    file_name = FileField('选择上传文件',validators=[FileRequired(), FileAllowed(['zip','rar','7z','tar.gz','ppt','pptx','xls','xlsx','doc','docx'], '*** zip/rar/7z/tar.gz/ppt/pptx/xls/xlsx/doc/docx file type only! ***')])
    submit = SubmitField('上传')

